package br.megareleased;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import br.megareleased.gui.TrayController;
import br.megareleased.model.Series;
import br.megareleased.rss.RSS;
import br.megareleased.rss.RSSController;
import br.megareleased.rss.RSSVerifierController;
import br.megareleased.tvshow.FollowController;

public class Main {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);

		TrayController trayController = TrayController.getInstance();
		trayController.startTray(display, shell);
		
		FollowController followController = FollowController.getInstance();
		followController.addToFollow(new Series("175001")); //Teen Wolf id
		followController.addToFollow(new Series("79545")); //Man vs. Wild id
		
		RSSController rssController = RSSController.getInstance();
		rssController.addRSS(new RSS("http://www.google.com/reader/public/atom/user%2F05547973623021449145%2Flabel%2Fdownload"));
		
		display.asyncExec(new Runnable() {
			public void run(){
				while(true) {
					RSSVerifierController rssVerifier = RSSVerifierController.getInstance();
					rssVerifier.execute();
					
					try { 
						Thread.sleep(60000);
					} catch( InterruptedException e ) {}
				}
			};
		});

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}